#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;

class Solution {
public:
    string removeDuplicates(string S) {
        vector<char> result;
        int i = 0;
        while(i<S.size()){
            if(result.empty()){
                result.push_back(S[i]);   
                ++i;
            }
            else{
                if(S[i]==result.back()){
                    result.pop_back();
                    ++i;
                }
                else{
                    result.push_back(S[i]);
                    ++i;
                }
            }
        }
        string T(result.begin(),result.end());
        return T;
    }
};


int main(){
    Solution S;
    cout<<S.removeDuplicates("abbaca")<<endl;
}